home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / util2 / iuwcltls.lha / src / getvolume.c < prev    next >
C/C++ Source or Header  |  1995-09-05  |  3KB  |  115 lines

  1. /* getvolume - get volume name of current dir or device
  2.  *
  3.  * Copyright (C) 1995 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation.  This software is provided "as is" without express or
  10.  * implied warranty.
  11.  *
  12.  * V1.0: 30/Jul/95
  13.  */
  14. #define THIS_PROGRAM    "getvolume"
  15. #define THIS_VERSION    "1.0"
  16.  
  17. #include <exec/types.h>
  18. #include <exec/libraries.h>
  19. #include <dos/dos.h>
  20. #include <dos/dosextens.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #define SysBase_DECLARED
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27.  
  28. extern struct Library *         SysBase;
  29.  
  30. static const char amiga_version[] = "\0$VER: " THIS_PROGRAM " " THIS_VERSION " (" __COMMODORE_DATE__ ")";
  31.  
  32. const char Template[] = "DEVICE,NOREQ/S";
  33. __aligned struct {
  34.     STRPTR  device;
  35.     LONG    noreq;
  36. } Args;
  37.  
  38.  
  39. void
  40. _main()
  41. {
  42.     struct RDArgs *rdargs;
  43.     __aligned struct InfoData info;
  44.     BOOL succ = FALSE;
  45.     UBYTE volume[258];
  46.     APTR win;
  47.     struct Process *thisProc = NULL;
  48.  
  49.     if( SysBase->lib_Version < 37 ) {
  50.         #define MESSAGE "requires AmigaOS 2.04 or higher\n"
  51.         Write(Output(), MESSAGE, sizeof(MESSAGE)-1);
  52.         _exit(RETURN_FAIL);
  53.         #undef MESSAGE
  54.     }
  55.  
  56.     if( rdargs = ReadArgs(Template, (LONG *)&Args, NULL) ) {
  57.         if( Args.noreq ) {
  58.             thisProc = (struct Process *)FindTask(NULL);
  59.             win = thisProc->pr_WindowPtr;
  60.             thisProc->pr_WindowPtr = (APTR)-1;
  61.         }
  62.         if( Args.device ) {
  63.             struct DevProc *devproc;
  64.  
  65.             if( devproc = GetDeviceProc(Args.device, NULL) ) {
  66.                 succ = (BOOL)DoPkt(devproc->dvp_Port, ACTION_DISK_INFO, MKBADDR(&info), 0, 0, 0, 0);
  67.                 FreeDeviceProc(devproc);
  68.             }
  69.         }
  70.         else
  71.             succ = Info(((struct Process *)FindTask(NULL))->pr_CurrentDir, &info);
  72.  
  73.         if( thisProc )
  74.             thisProc->pr_WindowPtr = win;
  75.  
  76.         FreeArgs(rdargs);
  77.     }
  78.  
  79.     if( succ ) {
  80.         struct DeviceList *dlist;
  81.  
  82.         switch( info.id_DiskType ) {
  83.             case ID_NO_DISK_PRESENT:
  84.                 SetIoErr(ERROR_NO_DISK);
  85.                 break;
  86.             case ID_DOS_DISK:
  87.             case ID_FFS_DISK:
  88.             case ID_INTER_DOS_DISK:
  89.             case ID_INTER_FFS_DISK:
  90.             case ID_FASTDIR_DOS_DISK:
  91.             case ID_FASTDIR_FFS_DISK:
  92.             case ID_MSDOS_DISK:
  93.                 if( dlist = BADDR(info.id_VolumeNode) ) {
  94.                     UBYTE *name;
  95.                     int len;
  96.  
  97.                     /* BCPL string -> C string */
  98.                     if( name = BADDR(dlist->dl_Name) ) {
  99.                         len  = *name++;
  100.                         strncpy(volume, (char *)name, len);
  101.                         volume[len++]   = '\n';
  102.                         volume[len] = '\0';
  103.                         PutStr(volume);
  104.                         _exit(RETURN_OK);
  105.                     }
  106.                 }
  107.             default:
  108.                 SetIoErr(ERROR_NOT_A_DOS_DISK);
  109.         }
  110.     }
  111.     PrintFault(IoErr(), THIS_PROGRAM);
  112.     _exit(RETURN_ERROR);
  113. }
  114.  
  115.